package com.ecspace.knowledgegraphapi.controller;


import com.alibaba.fastjson.JSONObject;
import com.ecspace.knowledgegraphapi.domain.dto.BusinessInfo;
import com.ecspace.knowledgegraphapi.domain.dto.NodeDTO;
import com.ecspace.knowledgegraphapi.domain.dto.NodeRelationDTO;
import com.ecspace.knowledgegraphapi.domain.entity.Node;
import com.ecspace.knowledgegraphapi.domain.vo.ResponseResult;
import com.ecspace.knowledgegraphapi.service.INodeService;
import com.ecspace.knowledgegraphapi.service.IRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/node")
public class NodeController {

    @Autowired
    private INodeService nodeService;



    @GetMapping("/list")
    public ResponseResult<List<Node>> listAll() {

        List<Node> list = nodeService.list();
        return ResponseResult.success(list);
    }



    @RequestMapping("/getById/{id}")
    public ResponseResult<Node> getById(@PathVariable("id") String id) {
        Node node = nodeService.getById(id);
        return ResponseResult.success(node);
    }


    @PostMapping("/saveNodeInfo")
    public ResponseResult<JSONObject> saveNodeInfo(@RequestBody NodeDTO nodeDTO) {

        String id = nodeService.saveOneNode(nodeDTO);
        JSONObject idObj = new JSONObject();
        idObj.put("id", id);
        return ResponseResult.success(idObj);
    }










}
